package Tests
{
	import Box2D.Common.b2Base;
	
	import Framework.Test;
	
	import Tests.ext.Buoyancy;
	import Tests.ext.CCD;
	
	import flash.display.Sprite;
	
	import mx.collections.ArrayCollection;
	import mx.collections.Sort;
	import mx.collections.SortField;
	
	public class TestEntries
	{
		[Bindable]
		public static var index:int;
		[Bindable]
		public static var current:Test;
		public static var container:Sprite;
		[Bindable]
		public static var entries:ArrayCollection =new ArrayCollection([
			{name:"Apply Force",cls:ApplyForce}
			,{name:"Breakable",cls:Breakable}
			,{name:"Bullet Test",cls:BulletTest}
			,{name:"Body Types",cls:BodyTypes}
			,{name:"PolyCollision",cls:PolyCollision}
			,{name:"Car",cls:Car} 
			,{name:"Cantilever",cls:Cantilever} 
			,{name:"Prismatic",cls:Prismatic} 
			,{name:"Time of Impact",cls:TimeOfImpact}
			,{name:"Theo Jansen's Walker",cls:TheoJansen}
			,{name:"Pinball",cls:PinBall}
			,{name:"Pyramid",cls:Pyramid}
			,{name:"Ray-Cast",cls:RayCast}
			,{name:"Edge Shapes",cls:EdgeShapes}
			,{name:"Revolute",cls:Revolute}
			,{name:"Dynamic Tree",cls:DynamicTreeTest}
			,{name:"Gears",cls:Gears}
			,{name:"Buoyancy[ext]",cls:Buoyancy}
			,{name:"Web",cls:Web}
			,{name:"CCD[ext]",cls:CCD}
		]);
		public static function load(index:int):void{
			TestEntries.index = index;
			if(current)
				current.world.Delete();
			current = null;
			var cls:Class = entries.getItemAt(index).cls;
			current =  new cls();
			current.container = container;
		}
		public static function loadNext():void{
			index++;
			if(index>=entries.length)
				index=entries.length-1;
			load(index);
		}
		public static function loadPrev():void{
			index--;
			if(index<0)
				index=0;
			load(index);
		}
		public static function reload():void{
			var sort:Sort = new Sort;
			sort.fields = [new SortField('name',true)];
			entries.sort = sort;
			entries.refresh()
			load(index);
		}
	}
}